package config

import (
	"regexp"
)

type ApplicationConfig struct {
	ApiKeys []string

	OpaqueErrors                       bool
	UseSubtleKeyComparison             bool
	DisableApiKeyRequirementForHttpGet bool
	HttpGetExemptedEndpoints           []*regexp.Regexp

	CORSAllowOrigins string
	Debug            bool
	CORS             bool
	CSRF             bool

	MachineTag string

	DBConfigPath string
}

type AppOption func(*ApplicationConfig)

func NewApplicationConfig(o ...AppOption) *ApplicationConfig {
	opt := &ApplicationConfig{}
	for _, oo := range o {
		oo(opt)
	}
	return opt
}

func WithApiKeys(apiKeys []string) AppOption {
	return func(opt *ApplicationConfig) {
		opt.ApiKeys = apiKeys
	}
}

func WithOpaqueErrors(opaqueErrors bool) AppOption {
	return func(opt *ApplicationConfig) {
		opt.OpaqueErrors = opaqueErrors
	}
}

func WithUseSubtleKeyComparison(useSubtleKeyComparison bool) AppOption {
	return func(opt *ApplicationConfig) {
		opt.UseSubtleKeyComparison = useSubtleKeyComparison
	}
}

func WithDisableApiKeyRequirementForHttpGet(disableApiKeyRequirementForHttpGet bool) AppOption {
	return func(opt *ApplicationConfig) {
		opt.DisableApiKeyRequirementForHttpGet = disableApiKeyRequirementForHttpGet
	}
}

func WithHttpGetExemptedEndpoints(httpGetExemptedEndpoints []*regexp.Regexp) AppOption {
	return func(opt *ApplicationConfig) {
		opt.HttpGetExemptedEndpoints = httpGetExemptedEndpoints
	}
}

func WithCORSAllowOrigins(corsAllowOrigins string) AppOption {
	return func(opt *ApplicationConfig) {
		opt.CORSAllowOrigins = corsAllowOrigins
	}
}
func WithCsrf(b bool) AppOption {
	return func(o *ApplicationConfig) {
		o.CSRF = b
	}
}

func WithCors(b bool) AppOption {
	return func(o *ApplicationConfig) {
		o.CORS = b
	}
}

func WithDebug(b bool) AppOption {
	return func(o *ApplicationConfig) {
		o.Debug = b
	}
}
func WithMachineTag(tag string) AppOption {
	return func(o *ApplicationConfig) {
		o.MachineTag = tag
	}
}

func WithDBConfigPath(path string) AppOption {
	return func(o *ApplicationConfig) {
		o.DBConfigPath = path
	}
}
